home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-09-23 | 116.8 KB | 4,027 lines |
-
-
- 6/24/81
-
-
-
-
-
-
-
-
-
-
-
- MATLAB Users' Guide
- May, 1981
-
-
- Cleve Moler
- Department of Computer Science
- University of New Mexico
-
-
- ABSTRACT. MATLAB is an interactive computer program
- that serves as a convenient "laboratory" for
- computations involving matrices. It provides easy
- access to matrix software developed by the LINPACK and
- EISPACK projects. The program is written in Fortran
- and is designed to be readily installed under any
- operating system which permits interactive execution of
- Fortran programs.
-
-
-
- CONTENTS
-
- 1. Elementary operations page 2
- 2. MATLAB functions 8
- 3. Rows, columns and submatrices 9
- 4. FOR, WHILE and IF 10
- 5. Commands, text, files and macros 12
- 6. Census example 13
- 7. Partial differential equation 19
- 8. Eigenvalue sensitivity example 23
- 9. Syntax diagrams 27
- 10. The parser-interpreter 31
- 11. The numerical algorithms 34
- 12. FLOP and CHOP 37
- 13. Communicating with other programs 41
- Appendix. The HELP file 46
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 6/24/81
-
-
-
-
-
-
-
-
-
-
-
- MATLAB Users' Guide
- November, 1980
-
-
- Cleve Moler
- Department of Computer Science
- University of New Mexico
-
-
-
- MATLAB is an interactive computer program that serves as a
- convenient "laboratory" for computations involving matrices. It
- provides easy access to matrix software developed by the LINPACK
- and EISPACK projects \1-3!. The capabilities range from standard
- tasks such as solving simultaneous linear equations and inverting
- matrices, through symmetric and nonsymmetric eigenvalue problems,
- to fairly sophisticated matrix tools such as the singular value
- decomposition.
-
- It is expected that one of MATLAB's primary uses will be in
- the classroom. It should be useful in introductory courses in
- applied linear algebra, as well as more advanced courses in
- numerical analysis, matrix theory, statistics and applications of
- matrices to other disciplines. In nonacademic settings, MATLAB
- can serve as a "desk calculator" for the quick solution of small
- problems involving matrices.
-
- The program is written in Fortran and is designed to be
- readily installed under any operating system which permits
- interactive execution of Fortran programs. The resources
- required are fairly modest. There are less than 7000 lines of
- Fortran source code, including the LINPACK and EISPACK
- subroutines used. With proper use of overlays, it is possible
- run the system on a minicomputer with only 32K bytes of memory.
-
- The size of the matrices that can be handled in MATLAB
- depends upon the amount of storage that is set aside when the
- system is compiled on a particular machine. We have found that
- an allocation of 5000 words for matrix elements is usually quite
- satisfactory. This provides room for several 20 by 20 matrices,
- for example. One implementation on a virtual memory system
- provides 100,000 elements. Since most of the algorithms used
- access memory in a sequential fashion, the large amount of
- allocated storage causes no difficulties.
-
-
-
-
-
-
-
-
-
-
- MATLAB, page 2
-
-
-
- In some ways, MATLAB resembles SPEAKEASY \4! and, to a
- lesser extent, APL. All are interactive terminal languages that
- ordinarily accept single-line commands or statements, process
- them immediately, and print the results. All have arrays or
- matrices as principal data types. But for MATLAB, the matrix is
- the only data type (although scalars, vectors and text are
- special cases), the underlying system is portable and requires
- fewer resources, and the supporting subroutines are more powerful
- and, in some cases, have better numerical properties.
-
- Together, LINPACK and EISPACK represent the state of the art
- in software for matrix computation. EISPACK is a package of over
- 70 Fortran subroutines for various matrix eigenvalue computations
- that are based for the most part on Algol procedures published by
- Wilkinson, Reinsch and their colleagues \5!. LINPACK is a
- package of 40 Fortran subroutines (in each of four data types)
- for solving and analyzing simultaneous linear equations and
- related matrix problems. Since MATLAB is not primarily concerned
- with either execution time efficiency or storage savings, it
- ignores most of the special matrix properties that LINPACK and
- EISPACK subroutines use to advantage. Consequently, only 8
- subroutines from LINPACK and 5 from EISPACK are actually
- involved.
-
- In more advanced applications, MATLAB can be used in
- conjunction with other programs in several ways. It is possible
- to define new MATLAB functions and add them to the system. With
- most operating systems, it is possible to use the local file
- system to pass matrices between MATLAB and other programs.
- MATLAB command and statement input can be obtained from a local
- file instead of from the terminal. The most power and
- flexibility is obtained by using MATLAB as a subroutine which is
- called by other programs.
-
- This document first gives an overview of MATLAB from the
- user's point of view. Several extended examples involving data
- fitting, partial differential equations, eigenvalue sensitivity
- and other topics are included. A formal definition of the MATLAB
- language and an brief description of the parser and interpreter
- are given. The system was designed and programmed using
- techniques described by Wirth \6!, implemented in nonrecursive,
- portable Fortran. There is a brief discussion of some of the
- matrix algorithms and of their numerical properties. The final
- section describes how MATLAB can be used with other programs.
- The appendix includes the HELP documentation available on-line.
-
-
- 1. Elementary operations
-
-
- MATLAB works with essentially only one kind of object, a
- rectangular matrix with complex elements. If the imaginary parts
- of the elements are all zero, they are not printed, but they
-
-
-
-
-
-
-
-
-
- MATLAB, page 3
-
-
-
- still occupy storage. In some situations, special meaning is
- attached to 1 by 1 matrices, that is scalars, and to 1 by n and m
- by 1 matrices, that is row and column vectors.
-
- Matrices can be introduced into MATLAB in four different
- ways:
- -- Explicit list of elements,
- -- Use of FOR and WHILE statements,
- -- Read from an external file,
- -- Execute an external Fortran program.
-
- The explicit list is surrounded by angle brackets, '<' and
- '>', and uses the semicolon ';' to indicate the ends of the rows.
- For example, the input line
-
- A = <1 2 3; 4 5 6; 7 8 9>
-
- will result in the output
-
- A =
-
- 1. 2. 3.
- 4. 5. 6.
- 7. 8. 9.
-
- The matrix A will be saved for later use. The individual
- elements are separated by commas or blanks and can be any MATLAB
- expressions, for example
-
- x = < -1.3, 4/5, 4*atan(1) >
-
- results in
-
- X =
-
- -1.3000 0.8000 3.1416
-
- The elementary functions available include sqrt, log, exp, sin,
- cos, atan, abs, round, real, imag, and conjg.
-
- Large matrices can be spread across several input lines,
- with the carriage returns replacing the semicolons. The above
- matrix could also have been produced by
-
- A = < 1 2 3
- 4 5 6
- 7 8 9 >
-
-
- Matrices can be input from the local file system. Say a
- file named 'xyz' contains five lines of text,
-
-
-
-
-
-
-
-
-
-
-
- MATLAB, page 4
-
-
-
- A = <
- 1 2 3
- 4 5 6
- 7 8 9
- >;
-
- then the MATLAB statement EXEC('xyz') reads the matrix and
- assigns it to A .
-
- The FOR statement allows the generation of matrices whose
- elements are given by simple formulas. Our example matrix A
- could also have been produced by
-
- for i = 1:3, for j = 1:3, a(i,j) = 3*(i-1)+j;
-
- The semicolon at the end of the line suppresses the printing,
- which in this case would have been nine versions of A with
- changing elements.
-
- Several statements may be given on a line, separated by
- semicolons or commas.
-
- Two consecutive periods anywhere on a line indicate
- continuation. The periods and any following characters are
- deleted, then another line is input and concatenated onto the
- previous line.
-
- Two consecutive slashes anywhere on a line cause the
- remainder of the line to be ignored. This is useful for
- inserting comments.
-
- Names of variables are formed by a letter, followed by any
- number of letters and digits, but only the first 4 characters are
- remembered.
-
- The special character prime (') is used to denote the
- transpose of a matrix, so
-
- x = x'
-
- changes the row vector above into the column vector
-
- X =
-
- -1.3000
- 0.8000
- 3.1416
-
-
- Individual matrix elements may be referenced by enclosing
- their subscripts in parentheses. When any element is changed,
- the entire matrix is reprinted. For example, using the above
- matrix,
-
-
-
-
-
-
-
-
-
- MATLAB, page 5
-
-
-
- a(3,3) = a(1,3) + a(3,1)
-
- results in
-
- A =
-
- 1. 2. 3.
- 4. 5. 6.
- 7. 8. 10.
-
-
- Addition, subtraction and multiplication of matrices are
- denoted by +, -, and * . The operations are performed whenever
- the matrices have the proper dimensions. For example, with the
- above A and x, the expressions A + x and x*A are incorrect
- because A is 3 by 3 and x is now 3 by 1. However,
-
- b = A*x
-
- is correct and results in the output
-
- B =
-
- 9.7248
- 17.6496
- 28.7159
-
- Note that both upper and lower case letters are allowed for input
- (on those systems which have both), but that lower case is
- converted to upper case.
-
- There are two "matrix division" symbols in MATLAB,